package com.api.service.impl;

import com.api.model.entity.UserIntegral;
import com.api.model.request.NullRequest;
import com.api.model.response.NullResponse;
import com.api.common.reqres.Request;
import com.api.common.reqres.Response;
import com.api.component.RequestComponent;
import com.api.component.ResponseComponent;
import com.api.mapper.ShippingAddressMapper;
import com.api.mapper.UserIntegralMapper;
import com.api.service.UserIntegralService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author cfp
 * @since 2019-10-14
 */
@Service
public class UserIntegralServiceImpl extends ServiceImpl<UserIntegralMapper, UserIntegral>
		implements UserIntegralService {
	@Autowired
	private UserIntegralMapper userIntegralMapper;
	@Autowired
	private RequestComponent requestComponent;
	@Autowired
	private ResponseComponent responseComponent;

	@Override
	public Response<NullResponse> userIntegral(Request<NullRequest> request) {
		// TODO Auto-generated method stub
		String userid = request.getHead().getUserid();
		LambdaQueryWrapper<UserIntegral> queryWrapper = new LambdaQueryWrapper<UserIntegral>();
		queryWrapper.eq(UserIntegral::getUserid, Long.valueOf(userid)).orderByDesc(UserIntegral::getCreatetime);
		List<UserIntegral> userIntegralList = userIntegralMapper.selectList(queryWrapper);
		if (CollectionUtils.isEmpty(userIntegralList)) {
			return responseComponent.toError("无积分记录");
		}
		return responseComponent.toSuccess(userIntegralList);
	}

}
